package com.xueshandai.db.migration.mode;

import com.alibaba.fastjson.JSON;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Zetas on 2014/12/13.
 */
public class LineData implements Serializable {

    private List<ColumnData> columnDataList;

    public LineData() {
        this.columnDataList = new ArrayList<ColumnData>();
    }

    public List<ColumnData> getColumnDataList() {
        return columnDataList;
    }

    public void setColumnDataList(List<ColumnData> columnDataList) {
        this.columnDataList = columnDataList;
    }

    public List<ColumnData> add(ColumnData columnData) {
        columnDataList.add(columnData);
        return columnDataList;
    }

    public String toJSON() {
        return JSON.toJSONString(this);
    }

    public static LineData parse(String json) {
        return JSON.parseObject(json, LineData.class);
    }

    public String getValue(String fieldName) {
        for (ColumnData columnData : columnDataList) {
            if ( columnData.getMetaData().getColumnName().equals(fieldName) ) {
                return columnData.getData();
            }
        }
        return null;
    }
}
